local extension = Package("heroes_ev7")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["heroes_ev7"] = "新约角色25-28",
  ["ev"] = "新约",
}

local miyu = General(extension, "ev__miyu", "ev", 4, 4, General.Female)

local yingxiongjueyi = fk.CreateTriggerSkill{
  name = "yingxiongjueyi",
  --frequency = Skill.Compulsory,
  events = {fk.RoundStart, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self) and player.room:getTag("RoundCount") > 1
    else
      return player:hasSkill(self) and target == player and player:getMark("@yingxiongjueyi-round") ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.RoundStart then
      local targets = table.map(table.filter(player.room.alive_players, function (p) return not EV.isFriend(player, p) end), Util.IdMapper)
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#yingxiongjueyi-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = tos[1]
        return true
      end
    else
      local prompt = "#yingxiongjueyi-recast"
      local cards = player:getCardIds("he")
      if player:getTableMark("@yingxiongjueyi-round")[1] >= player:getTableMark("@yingxiongjueyi-round")[3] then
        prompt = "#yingxiongjueyi-show"
        cards = table.filter(player:getCardIds("h"), function (id)
          return Fk:getCardById(id).color == Card.Black and Fk:getCardById(id):getMark("@@shown-inhand") == 0
        end)
      end
      local ids = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), prompt)
      if #ids > 0 then
        self.cost_data = ids
        return true
      end 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local n = 0
      local logic = room.logic
      local current_event = logic:getCurrentEvent()
      local all_round_events = logic.event_recorder[GameEvent.Round]--获取所有轮次事件
      if type(all_round_events) == "table" then
        local index = #all_round_events
        if index > 0 then
          local round_event = current_event:findParent(GameEvent.Round)--获取此轮
          if round_event ~= nil then
            index = index - 1
          end
          if index > 0 then--若存在上一轮
            current_event = all_round_events[index]--获取上一轮
            local events = U.getEventsByRule(room, GameEvent.UseCard, 999, function (e)
              local use = e.data[1]
              return use.from == self.cost_data
            end, current_event.id)
            n = #events
          end
        end
      end
      --room:setBanner("@yingxiongjueyi", n)
      room:setPlayerMark(player, "@yingxiongjueyi-round", {0, "/", n})
    else
      if player:getTableMark("@yingxiongjueyi-round")[1] < player:getTableMark("@yingxiongjueyi-round")[3] then
        room:recastCard(self.cost_data, player, self.name)
        if Fk:getCardById(self.cost_data[1]).suit == Card.Heart then
          player:drawCards(1, self.name)
        end
      else
        EV.OpenCards(room, player, self.cost_data, self.name)
        data.unoffsetableList = table.map(room.alive_players, Util.IdMapper)
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("@yingxiongjueyi-round") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local round_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
    local events = U.getEventsByRule(player.room, GameEvent.UseCard, 999, function (e)
      local use = e.data[1]
      return use.from == player.id
    end, round_event.id)
    local n = player:getTableMark("@yingxiongjueyi-round")[3]
    player.room:setPlayerMark(player, "@yingxiongjueyi-round", {#events, "/", n})
  end
}

local zhufuzhiyuan = fk.CreateTriggerSkill{
  name = "zhufuzhiyuan",
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
      U.getEventsByRule(room, GameEvent.UseCard, 999, function (e)
        local use = e.data[1]
        if not room:getPlayerById(use.from).dead then
          room:addPlayerMark(room:getPlayerById(use.from), "zhufuzhiyuan-round")
        end
      end, round_event.id)
      local n = 0
      for _, p in ipairs(room.alive_players) do
        n = math.max(n, p:getMark("zhufuzhiyuan-round"))
      end
      return player:getMark("zhufuzhiyuan-round") >= n
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player, true)) do
      local cards = room:askForCard(p, 1, 1, true, self.name, true, ".|.|heart,diamond", "#zhufuzhiyuan")
      if #cards > 0 then
        if Fk:getCardById(cards[1]):getMark("@@shown-inhand") == 0 then
          EV.OpenCards(room, p, cards, self.name)
        else
          room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, self.name, "", true)
        end
      end
    end
  end,

  --[[refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_refresh = function(self, event, target, player, data)
    local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
    local events = U.getEventsByRule(player.room, GameEvent.UseCard, 999, function (e)
      local use = e.data[1]
      return use.from == player.id
    end, round_event.id)
    local n = player:getTableMark("@yingxiongjueyi-round")[3]
    player.room:setPlayerMark(player, "@yingxiongjueyi-round", {#events, "/", n})
  end]]
}

miyu:addSkill(yingxiongjueyi)
miyu:addSkill(zhufuzhiyuan)

Fk:loadTranslationTable{
  ["ev__miyu"] = "米浴",
  ["designer:ev__miyu"] = "KINGDOM43",
  ["yingxiongjueyi"] = "英雄决意",
  [":yingxiongjueyi"] = "每轮开始时，你可选择一名非己方角色，当你使用牌时，若你于本轮内使用过的牌数小于/不小于其于上轮内使用过的牌数，你可重铸牌，若为红桃牌，你摸一张牌/明置一张黑色手牌，令你使用的此牌不是牌的合法目标。",
  ["@yingxiongjueyi-round"] = "英雄决意",
  ["#yingxiongjueyi-choose"] = "英雄决意：你可选择一名非己方角色",
  ["#yingxiongjueyi-recast"] = "英雄决意：你可以重铸一张牌",
  ["#yingxiongjueyi-show"] = "英雄决意：你可以明置一张黑色手牌",
  ["zhufuzhiyuan"] = "祝福之愿",
  [":zhufuzhiyuan"] = "每轮结束时，若你为于本轮内使用牌数最大的角色，其他角色各可选择一项：1.明置一张红色手牌；2.将一张红色明置手牌交给你。",
  ["#zhufuzhiyuan"] = "请选择一张红色手牌",

  ["$yingxiongjueyi1"] = "（日）呜，必须得更加努力！",
  ["$yingxiongjueyi2"] = "（日）米浴也能……绽放光彩！",
  ["$zhufuzhiyuan"] = "（日）想给大家带来幸福……米浴，出发了！",
  ["~ev__miyu"] = "（日）唔。。输了。。",
}

local qianhuyouli = General(extension, "ev__qianhuyouli", "ev", 3, 3, General.Female)

local cengdiechengshi = fk.CreateTriggerSkill{
  name = "cengdiechengshi",
  derived_piles = {"uzi&"},
  events = {fk.GameStart, fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self.name)
    else
      if player:hasSkill(self.name) then
        for _, move in ipairs(data) do
          if move.from == player.id and move.extra_data and move.extra_data.uzi then
            local uzicount = player.room:getBanner("@uzicount")
            return uzicount == 1 or uzicount == 5 or uzicount == 14
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      player:throwAllCards("h")
      player:addToPile("uzi&", room:getNCards(1), true, self.name)
    else
      local uzicount = player.room:getBanner("@uzicount")
      if uzicount == 1 then
        player:addToPile("uzi&", room:getNCards(4), true, self.name)
      elseif uzicount == 5 then
        player:addToPile("uzi&", room:getNCards(9), true, self.name)
      elseif uzicount == 14 then
        player:addToPile("uzi&", room:getNCards(16), true, self.name)
      end
    end
    room:addPlayerMark(player, "@cengdiechengshi")
  end,

  refresh_events = {fk.BeforeCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial and player:getPileNameOfId(info.cardId) == "uzi&" then
              return true
            end
          end
        elseif move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end      
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        local ids = {}
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerSpecial and player:getPileNameOfId(info.cardId) == "uzi&" then
            table.insertIfNeed(ids, info.cardId)
          end
        end
        if #ids > 0 then
          local mark = player:getTableMark("uzi-record")
          table.insertTableIfNeed(mark, ids)
          player.room:setPlayerMark(player, "uzi-record", mark)
          local uzicount = player.room:getBanner("@uzicount")
          if not uzicount then uzicount = 0 end
          uzicount = uzicount + #ids
          player.room:setBanner("@uzicount", uzicount)
          move.extra_data = move.extra_data or {}
          move.extra_data.uzi = ids
        end
      elseif move.to == player.id and move.toArea == Card.PlayerHand then
        local mirror_moves = {}
        local ids = {}
        local move_info = {}
        local mirror_info = move.moveInfo
        for _, info in ipairs(move.moveInfo) do
          table.insert(ids, info.cardId)
        end
        if #mirror_info > 0 then
          move.moveInfo = move_info
          local mirror_move = table.clone(move)
          mirror_move.to = nil
          mirror_move.toArea = Card.Void
          mirror_move.moveInfo = mirror_info
          mirror_move.moveMark = nil
          mirror_move.moveVisible = true
          table.insert(mirror_moves, mirror_move)
        end
        if #ids > 0 then
          table.insertTable(data, mirror_moves)
        end
      end
    end  
  end,
}

local zhongmolvxing = fk.CreateTriggerSkill{
  name = "zhongmolvxing",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.type ~= Card.TypeEquip and #player:getPile("uzi&") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#zhongmolvxing:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("uzi&"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true)
    EV.nullifiedCard(data, data.card, player)
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.CardResponding},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.contains(player:getTableMark("uzi-record"), data.card.id)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "zhongmolvxing-turn")
  end,
}

local zhongmolvxing_effect = fk.CreateProhibitSkill{
  name = "#zhongmolvxing_effect",
  prohibit_use = function(self, player, card)
    return player:hasSkill("zhongmolvxing") and player:getPileNameOfId(card.id) == "uzi&"
    and player:getMark("zhongmolvxing-turn") >= player:getMark("@cengdiechengshi")
  end,
  prohibit_response = function(self, player, card)
    return player:hasSkill("zhongmolvxing") and player:getPileNameOfId(card.id) == "uzi&"
    and player:getMark("zhongmolvxing-turn") >= player:getMark("@cengdiechengshi")
  end,
}
zhongmolvxing:addRelatedSkill(zhongmolvxing_effect)
qianhuyouli:addSkill(cengdiechengshi)
qianhuyouli:addSkill(zhongmolvxing)

Fk:loadTranslationTable{
  ["ev__qianhuyouli"] = "千户尤莉",
  ["designer:ev__qianhuyouli"] = "竹芊子",
  ["cengdiechengshi"] = "层叠城市",
  ["@cengdiechengshi"] = "层叠城市",
  [":cengdiechengshi"] = "锁定技，游戏开始时，你废除手牌区，将牌堆顶的一张牌置于角色牌上，称为“物资”。当你失去“物资”后，若已失去的“物资”数为1/5/14，你将牌堆顶的四/九/十六张牌置于角色牌上，称为“物资”。",
  ["uzi&"] = "物资",
  ["@uzicount"] = "失去物资数：",
  ["zhongmolvxing"] = "终末旅行",
  [":zhongmolvxing"] = "当你成为非装备牌的目标后，你可将所有“物资”置入弃牌堆，令此牌对你无效。回合技（X），你可使用或打出“物资”（X为你发动过“层叠城市”的次数）。",
  ["#zhongmolvxing"] = "你可将所有“物资”置入弃牌堆，令%arg对你无效",
  ["#zhongmolvxing_effect"] = "终末旅行",
}

local jingyuan = General(extension, "ev__jingyuan", "ev", 3)

local ev__shence = fk.CreateTriggerSkill{
  name = "ev__shence",
  anim_type = "defensive",
  mute = true,
  events = {fk.TurnStart, fk.TargetConfirmed, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player:hasSkill(self)
    elseif event == fk.TargetConfirmed then
      return player:hasSkill(self) and target == player and data.from ~= player.id and player:getMark("ev__shence-turn") == 0
    elseif event == fk.CardUseFinished then
      return player:hasSkill(self) and data.extra_data and data.extra_data.shence and data.extra_data.shence == player.id
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".", "#ev__shence-card")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    elseif event == fk.TargetConfirmed then
      return player.room:askForSkillInvoke(player, self.name, nil, "#ev__shence-invoke")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:notifySkillInvoked(player, self.name, "control")
      local choice = room:askForChoice(player, {"top", "bottom"}, self.name)
      local n = 1 
      if choice == "bottom" then
        n = -1
        player:broadcastSkillInvoke(self.name, 2)
      else
        player:broadcastSkillInvoke(self.name, 1)
      end
      EV.choicelog(player, choice)
      room:moveCards({
        ids = self.cost_data,
        from = player.id,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = self.name,
        drawPilePosition = n,
      })
    elseif event == fk.TargetConfirmed then
      room:addPlayerMark(player, "ev__shence-turn")
      local choice = room:askForChoice(player, {"top", "bottom"}, self.name)
      EV.choicelog(player, choice)
      local cards = room:getNCards(1, choice)
      room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name)
      local card = Fk:getCardById(cards[1])
      if card.type == data.card.type then
        player:broadcastSkillInvoke(self.name, 3)
        room:notifySkillInvoked(player, self.name, "defensive")
        EV.nullifiedCard(data, data.card, player)
      end
      if card.suit == data.card.suit then
        data.extra_data = data.extra_data or {}
        data.extra_data.shence = player.id
      end
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true)
    else
      player:broadcastSkillInvoke(self.name, 4)
      room:notifySkillInvoked(player, self.name, "offensive")
      U.askForUseVirtualCard(room, player, "ev_thunder__slash", nil, self.name, nil, true, true, false, true)
    end
  end,
}

local shezhaoweiling = fk.CreateTriggerSkill{
  name = "shezhaoweiling",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local uses = room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id end, Player.HistoryRound)
    local responses = room.logic:getEventsOfScope(GameEvent.RespondCard, 999, function(e)
      local response = e.data[1]
      return response.from == player.id end, Player.HistoryRound)
    self.cost_data = #uses + #responses
    return (self.cost_data > #room.alive_players or self.cost_data < target.seat) and self.cost_data > 0
    and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#shezhaoweiling-invoke:::"..self.cost_data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(self.cost_data)
    local can_use = table.simpleClone(ids)
    room:moveCardTo(ids, Card.Processing, nil, fk.ReasonJustMove, self.name)
    for i = 1, 3, 1 do
      local use = U.askForUseRealCard(room, player, ids, ".", self.name, "#shezhaoweiling-use",
      {expand_pile = can_use, bypass_times = true}, false, true)
      if use then
        for _, id in ipairs(ids) do
          if Fk:getCardById(id):getTypeString() == use.card:getTypeString() then
            table.removeOne(can_use, id)
          end
        end
        table.removeOne(ids, use.card:getEffectiveId())
      else
        break
      end 
    end
    room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true)
  end,
}

jingyuan:addSkill(ev__shence)
jingyuan:addSkill(shezhaoweiling)

Fk:loadTranslationTable{
  ["ev__jingyuan"] = "景元",
  ["designer:ev__jingyuan"] = "K之卡",
  ["ev__shence"] = "神策",
  [":ev__shence"] = "回合技（始），你可将一张牌置于牌堆顶或底。回合技，当你成为其他角色使用牌的目标后，你可亮出牌堆顶或底的一张牌，若这两张牌：类别相同，此牌对你无效；花色相同，你于此牌结算结束后视为使用雷【杀】。",
  ["#ev__shence-card"] = "神策：你可将一张牌置于牌堆顶或底",
  ["#ev__shence-invoke"] = "神策：你可亮出牌堆顶或底的一张牌",
  ["shezhaoweiling"] = "摄召威灵",
  ["#shezhaoweiling-invoke"] = "摄召威灵：你可以亮出牌堆顶的%arg张牌",
  ["#shezhaoweiling-use"] = "摄召威灵：你可以使用其中一张牌",
  [":shezhaoweiling"] = "轮次技，一名角色的回合结束时，若X大于角色数或小于其座次号，你可亮出牌堆顶的X张牌，依次使用其中每种类别的各一张牌（X为你于本轮内使用或打出过的牌数）。",

  ["$ev__shence1"] = "（控顶）时不我待。",
  ["$ev__shence2"] = "（控底）该出奇兵了。",
  ["$ev__shence3"] = "（无效）哼，破绽百出。",
  ["$ev__shence4"] = "（雷杀）雷霆，在此！",
  ["$shezhaoweiling"] = "煌煌威灵，遵吾敕命。斩无赦！",
  ["~ev__jingyuan"] = "久疏战阵了…",
}

local Muelsyse = General(extension, "ev__muelsyse", "ev", 3, 3, General.Female)

local feishangshiying = fk.CreateTriggerSkill{
  name = "feishangshiying",
  events = {fk.EventPhaseStart, fk.CardUsing, fk.EventPhaseEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    else
      return target == player and player:hasSkill(self) and player.phase == Player.Play and player:getMark("feishangshiying-turn") ~= 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local choice = room:askForChoice(player, {"0", "3"}, self.name)
      room:setPlayerMark(player, "@fssy-phase", tonumber(choice))
      if choice == "0" then
        room:setPlayerMark(player, "feishangshiying-turn", "ev__slash")
      elseif choice == "3" then
        room:setPlayerMark(player, "feishangshiying-turn", "ev__dismantlement")
      end
    elseif event == fk.CardUsing then
      if player:getMark("feishangshiying-turn") == "ev__slash" then
        room:addPlayerMark(player, "@fssy-phase")
      else
        room:removePlayerMark(player, "@fssy-phase")
      end
    elseif event == fk.EventPhaseEnd then
      local pattern = player:getMark("feishangshiying-turn")
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p) return player:distanceTo(p) == player:getMark("@fssy-phase") - 1 end), Util.IdMapper)
      if #targets > 0 then
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#feishangshiying:::"..player:getMark("@fssy-phase") - 1, self.name, false)
        if #to > 0 then
          --U.askForUseVirtualCard(room, target, pattern, nil, self.name)
          room:useVirtualCard(pattern, nil, player, room:getPlayerById(to[1]), self.name, true)
        end
      end
    end
  end,
}

local feishangshiying_attackrange = fk.CreateAttackRangeSkill{
  name = "#feishangshiying_attackrange",
  fixed_func = function (self, from)
    if from:hasSkill("feishangshiying") and from.phase == Player.Play and from:getMark("feishangshiying-turn") ~= 0 then
      return from:getMark("@fssy-phase")
    end
  end,
}

local feishangshiying_prohibit = fk.CreateProhibitSkill{--锁攻击范围优先级低，限制使用杀的目标
  name = "#feishangshiying_prohibit",
  is_prohibited = function(self, from, to, card)
    if card.trueName == "slash" and from:hasSkill(self) and from:getMark("feishangshiying-turn") ~= 0 then
      return from:distanceTo(to) > from:getMark("@fssy-phase")
    end
  end,
}


local jingshuishengming = fk.CreateTriggerSkill{
  name = "jingshuishengming",
  anim_type = "drawcard",
  events = {fk.RoundStart, fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self)
    else
      if player:hasSkill(self) and #player:getTableMark("jingshuishengming-round") > 0 then
        local to = player.room:getPlayerById(player:getTableMark("jingshuishengming-round")[1])
        return player:getHandcardNum() == to:getHandcardNum() and not to.dead
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.RoundStart then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#jingshuishengming", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      player:drawCards(1, self.name)
      room:setPlayerMark(player, "jingshuishengming-round", {self.cost_data})
      room:addPlayerMark(room:getPlayerById(self.cost_data), "@@jingshuishengming-round")
    else
      local to = player.room:getPlayerById(player:getTableMark("jingshuishengming-round")[1])
      local all_names = U.getAllCardNames("bt", false)
      local names = {}
      for _, card in ipairs(all_names) do
        local c = Fk:cloneCard(card)
        c.skillName = self.name
        if player:canUse(c) and not player:prohibitUse(c) then
          for _, s in ipairs(player.player_skills) do
            if s:isPlayerSkill(player) then
              if string.find(Fk:translate(":"..s.name, "zh_CN"), "【"..Fk:translate(c.name, "zh_CN").."】") or
                string.find(Fk:translate(":"..s.name, "zh_CN"), Fk:translate(c.name, "zh_CN")[1].."【"..Fk:translate(c.trueName, "zh_CN").."】") then
                table.insertIfNeed(names, c.name)
              end
            end
          end
          for _, s in ipairs(to.player_skills) do
            if s:isPlayerSkill(to) then
              if string.find(Fk:translate(":"..s.name, "zh_CN"), "【"..Fk:translate(c.name, "zh_CN").."】") or
                string.find(Fk:translate(":"..s.name, "zh_CN"), Fk:translate(c.name, "zh_CN")[1].."【"..Fk:translate(c.trueName, "zh_CN").."】") then
                table.insertIfNeed(names, c.name)
              end
            end
          end
        end
      end
      if #names > 0 then
        local choices = U.prepareDeriveCards(room, table.map(names, function (name) return {name, Card.NoSuit, 0} end), "jingshuishengming")
        if #choices > 0 then
          local use = U.askForUseRealCard(room, player, choices, nil, self.name, "请选择视为使用的牌",
            {expand_pile = choices, bypass_times = true}, true, true)
          if use then
            local to_use = {
              card = Fk:cloneCard(use.card.name),
              from = player.id,
              tos = use.tos,
              skillName = self.name,
              extraUse = true,
            }
            player.room:useCard(to_use)
          end
        end
      end  
    end
  end,
}



feishangshiying:addRelatedSkill(feishangshiying_attackrange)
feishangshiying:addRelatedSkill(feishangshiying_prohibit)
Muelsyse:addSkill(feishangshiying)
Muelsyse:addSkill(jingshuishengming)

Fk:loadTranslationTable{
  ["ev__muelsyse"] = "缪尔赛思",
  ["designer:ev__muelsyse"] = "幽蝶化烬",
  ["cv:ev__muelsyse"] = "王雅欣",
  ["feishangshiying"] = "非熵适应",
  ["@fssy-phase"] = "非熵适应",
  [":feishangshiying"] = "出牌阶段开始时，你将X改为0/3，且你使用牌时令X+1/-1，直至本阶段结束；本阶段结束时，你视为对距离为X-1的一名角色使用【杀】/【破坏工作】（X为你的攻击范围）。",
  ["#feishangshiying"] = "请选择一名距离%arg的角色",
  ["jingshuishengming"] = "净水生命",
  [":jingshuishengming"] = "每轮开始时，你可选择一名其他角色，摸一张牌；此轮结束时，若你与其的手牌数相等，你视为使用你或其技能描述中含有的一张基础牌或即时魔法牌。",
  ["#jingshuishengming"] = "净水生命：你可选择一名其他角色",
  ["@@jingshuishengming-round"] = "净水生命",

  ["$feishangshiying1"] = "阳光有点辣，我先休息一会。",
  ["$feishangshiying2"] = "或许，我应该先分配一下任务？",
  ["$jingshuishengming1"] = "如水随形。",
  ["$jingshuishengming2"] = "让恩怨随水流淌吧。",
  ["~ev__muelsyse"] = "幻象引开他们了，我们走这边吧。",
}

local shuangwolun = General(extension, "ev__shuangwolun", "ev", 3, 3, General.Female)

local wolunpenshe = fk.CreateTriggerSkill{
  name = "wolunpenshe",
  frequency = Skill.Compulsory,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)-- and player.room:getTag("RoundCount") == 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = math.min(room:getTag("RoundCount"), 4)
    player:drawCards(4 - n, self.name)
    if n == 4 then
      room:askForDiscard(player, 1, 1, true, self.name, false)
    end
  end,
}

local yongbuyanqi = fk.CreateTriggerSkill{
  name = "yongbuyanqi",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 then
      for _, move in ipairs(data) do
        return move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from == player.id
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    --player:drawCards(1, self.name)
    local names = player:getTableMark("@$yongbuyanqi")
    if #names > 0 then
      local choice = U.askForChooseCardNames(player.room, player, names, 1, 1, self.name, "请选择视为使用的牌")
      U.askForUseVirtualCard(player.room, player, choice[1], nil, self.name)
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and EV.isFriend(player, target) and table.contains(TargetGroup:getRealTargets(data.tos), player.id)
    and data.card.color == Card.Red
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("@$yongbuyanqi")
    table.insertIfNeed(mark, data.card.name)
    player.room:setPlayerMark(player, "@$yongbuyanqi", mark)
  end,
}

shuangwolun:addSkill(wolunpenshe)
shuangwolun:addSkill(yongbuyanqi)

Fk:loadTranslationTable{
  ["ev__shuangwolun"] = "双涡轮",
  ["designer:ev__shuangwolun"] = "KINGDOM43",
  ["wolunpenshe"] = "涡轮喷射",
  [":wolunpenshe"] = "锁定技，每轮开始时，你摸4-X张牌；然后若X为4，你弃置一张牌（X为轮数且至多为4）。",
  ["yongbuyanqi"] = "永不言弃",
  ["@$yongbuyanqi"] = "永不言弃",
  [":yongbuyanqi"] = "回合技，当你因弃置而失去牌后，你可视为使用其他己方角色对你使用过的一张红色牌。",

  ["$wolunpenshe1"] = "（日）全力冲刺！",
  ["$wolunpenshe2"] = "（日）涡轮全开！",
  ["$yongbuyanqi1"] = "（日）下次涡轮会甩掉所有人啦！",
  ["$yongbuyanqi2"] = "（日）唔唔唔……下次一定一定会赢啦！",
  ["~ev__shuangwolun"] = "（日）噗咻……引擎故障啦～",
}

local jinnaluo = General(extension, "ev__jinnaluo", "ev", 3, 3, General.Female)

local ev__tiaolv = fk.CreateViewAsSkill{
  name = "ev__tiaolv",
  pattern = ".",
  interaction = function()
    local all_names = Self:getTableMark("@$ev__tiaolv")
    local n = Self:getMark("@ev__tiaolv")
    local names = {all_names[n]}
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    if #cards ~= 0 then return end
    --card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:askForDiscard(player, 1, 1, true, self.name, false, ".")
    local n = player:getMark("@ev__tiaolv")
    n = n + 1
    if n > 5 then n = 1 end
    player.room:setPlayerMark(player, "@ev__tiaolv", n)
  end,
  enabled_at_play = function(self, player)
    return not player:isNude()
  end,
  enabled_at_response = function(self, player)
    return not player:isNude()
  end,
}

local tiaolv_trigger = fk.CreateTriggerSkill{
  name = "#tiaolv_trigger",
  mute = true,
  refresh_events = {fk.EventAcquireSkill, fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventAcquireSkill then
        return data.name == "ev__tiaolv"
      else
        return player:usedSkillTimes("ev__ji", Player.HistoryGame) > 0
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:setPlayerMark(player, "@ev__tiaolv", 1)
      player.room:setPlayerMark(player, "@$ev__tiaolv", {"ev__slash", "thorn_circle", "ev__dismantlement", "ev__nullification", "ev__peach"})
    else
      player.room:setPlayerMark(player, "@$ev__tiaolv", {"ev__slash", "thorn_circle", "ev__dismantlement", "ev__nullification", "ev__peach"})
    end
  end,
}

local ev__xu = fk.CreateTriggerSkill{
  name = "ev__xu",
  events = {fk.CardUsing},
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)-- and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card_type = data.card.type
    local logic = room.logic
    local events = logic:getEventsOfScope(GameEvent.UseCard, 2, function (e)
        local last_use = e.data[1]
        if last_use.from == player.id and last_use.card.type == card_type then
          return true
        end
        return false
      end, Player.HistoryTurn)
    if #events <= 1 then
      local ids = EV.getCenterArea(room)
      local cards = table.filter(ids, function (id) return Fk:getCardById(id).type == data.card.type end)
      if #cards > 0 then
        local choice = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "请选择获得的牌")
        room:moveCardTo(choice[1], Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true)
      end
    else
      local n = player:getMark("@ev__tiaolv")
      n = n + 1
      if n > 5 then n = 1 end
      room:setPlayerMark(player, "@ev__tiaolv", n)
    end
  end,
}

local ev__ji = fk.CreateActiveSkill{
  name = "ev__ji",
  anim_type = "drawcard",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local cards = from:getCardIds(Player.Hand)
    room:throwCard(cards, self.name, from, from)
    room:drawCards(from, #cards, self.name)
    local tiaolv = from:getTableMark("@$ev__tiaolv")
    local names = table.map(table.map(table.filter(cards, function (id) return Fk:getCardById(id).type ~= Card.TypeEquip end), Util.Id2CardMapper), Util.NameMapper)
    names = room:askForChoices(from, names, 0, #names, self.name, "#ev__ji-choice", false)
    for _, name in ipairs(names) do
      local choices = table.filter(tiaolv, function (n) return Fk:cloneCard(n).type == Fk:cloneCard(name).type end)
      if #choices > 0 then
        local choice = room:askForChoice(from, choices, self.name, "#ev__ji:::"..name)
        local n = table.indexOf(tiaolv, choice)
        tiaolv[n] = name
      end
    end
    room:setPlayerMark(from, "@$ev__tiaolv", tiaolv)
  end
}
ev__tiaolv:addRelatedSkill(tiaolv_trigger)
jinnaluo:addSkill(ev__tiaolv)
jinnaluo:addSkill(ev__xu)
jinnaluo:addSkill(ev__ji)

Fk:loadTranslationTable{
  ["ev__jinnaluo"] = "紧那罗",
  ["designer:ev__jinnaluo"] = "小樱",
  ["ev__tiaolv"] = "调律",
  [":ev__tiaolv"] = "转换技，你可弃置一张牌，视为使用或打出①【杀】②【荆棘之环】③【破坏行动】④【魔法禁令】⑤【茶】。",
  ["ev__xu"] = "序",
  [":ev__xu"] = "当你使用牌时，若为/不为你于本回合内首次使用此类别的牌，你可获得于当前回合内置入弃牌堆的与之类别相同的一张牌/将“调律”转换至下一项。",
  ["@ev__tiaolv"] = "调律",
  ["@$ev__tiaolv"] = "牌名",
  ["ev__ji"] = "急",
  [":ev__ji"] = "限定技，出牌阶段，你可弃置所有手牌，摸等量张牌，用以此法弃置的牌含有的任意个牌名替换“调律”中的与之类别相同的等量个选项，直至你的下回合开始。",
  ["#ev__ji-choice"] = "请选择任意个牌名",
  ["#ev__ji"] = "请选择用%arg替换的牌名",
}

local shengwangguanghuan = General(extension, "ev__shengwangguanghuan", "ev", 4, 4, General.Female)

local ConvertType = function(value, input_type, output_type)
  local mapper = {
    ["int"] = {Card.TypeBasic, Card.TypeTrick, Card.TypeEquip, Card.SubtypeWeapon, Card.SubtypeArmor, Card.SubtypeTreasure, Card.SubtypeDelayedTrick},
    ["str"] = {"basic", "trick", "equip", "weapon", "armor", "treasure", "delayedtrick"},
  }
  return mapper[output_type][table.indexOf(mapper[input_type], value)]
end

local suoweiyiliu = fk.CreateTriggerSkill{
  name = "suoweiyiliu",
  --frequency = Skill.Compulsory,
  events = {fk.RoundStart, fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local n = room:getTag("RoundCount")
      local choice = ""
      local all_choices = {"equip", "trick", "basic"}
      if player:usedSkillTimes("woxingwolu", Player.HistoryGame) > 0 then
        choice = room:askForChoice(player, all_choices, self.name)
      elseif n <= 3 then
        choice = all_choices[n]
      end
      if choice == "" then return end
      room:setPlayerMark(player, "@[cardtypes]suoweiyiliu-round", {ConvertType(choice, "str", "int")})
    else
      if #player:getTableMark("@suoweiyiliu-round") > 0 then
        if player:getTableMark("@suoweiyiliu-round")[1] >= player:getTableMark("@suoweiyiliu-round")[3] then
          player:drawCards(2, self.name)
        else
          room:askForDiscard(player, 1, 1, true, self.name, false)
        end
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("@[cardtypes]suoweiyiliu-round") ~= 0
    and data.card.type == player:getTableMark("@[cardtypes]suoweiyiliu-round")[1]
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local record = 0
    if #player:getTableMark("@suoweiyiliu-round") > 0 then
      record = player:getTableMark("@suoweiyiliu-round")[3]
    end
    --if room:getBanner("@suoweiyiliu_record") then record = room:getBanner("@suoweiyiliu_record") end
    local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
    local n = #U.getEventsByRule(room, GameEvent.UseCard, 999, function (e)
      local use = e.data[1]
      return use.from == target.id and use.card.type == player:getTableMark("@[cardtypes]suoweiyiliu-round")[1]
    end, round_event.id)
    if n > record then record = n end
    if target == player then
      room:setPlayerMark(player, "@suoweiyiliu-round", {n, "/", record})
    else
      local count = 0
      if #player:getTableMark("@suoweiyiliu-round") > 0 then
        count = player:getTableMark("@suoweiyiliu-round")[1]
      end
      room:setPlayerMark(player, "@suoweiyiliu-round", {count, "/", record})
    end
  end
}

local function GetCardsUsedThisRound(player)
  --[[local cards = {}
  local round_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
  U.getEventsByRule(player.room, GameEvent.UseCard, 999, function (e)
    local use = e.data[1]
    if use.from == player.id then
      local ids = {}
      if use.card:isVirtual() then
        ids = use.card.subcards
      else
        ids = {use.card.id}
      end
      for _, id in ipairs(ids) do
        if player.room:getCardArea(id) == Card.DiscardPile then
          table.insert(cards, id)
        end
      end
    end
  end, round_event.id)
  return cards]]
  local ids = {}
  local logic = player.room.logic
  local events = logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable
  if not logic:getCurrentEvent():findParent(GameEvent.Round, true) then return {} end
  local end_id = logic:getCurrentEvent():findParent(GameEvent.Round, true).id
  for i = #events, 1, -1 do
    local e = events[i]
    if e.id < end_id then break end
    for _, move in ipairs(e.data) do
      if move.from and move.from == player.id and move.moveReason == fk.ReasonUse then
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(ids, info.cardId)
        end
      end
    end
  end
  local cards = table.simpleClone(ids)
  for _, id in ipairs(cards) do
    if player.room:getCardArea(id) ~= Card.DiscardPile then
      table.removeOne(ids, id)
    end
  end
  return ids
end

local prideofking = fk.CreateTriggerSkill{
  name = "prideofking",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 and player:getMaxCards() > 0 then
      for _, move in ipairs(data) do
        return move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from == player.id
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    --player:drawCards(1, self.name)
    local cards = GetCardsUsedThisRound(player)
    local n = player:getMaxCards()
    if #cards > 0 then
      if #cards <= n then
        player.room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true)
      else
        local ids, _ = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "#prideofking:::"..n, nil, n, n)
        player.room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true)
      end
    end
    if n > 1 then
      if player:getMark("AddMaxCards") > 0 then
        player.room:removePlayerMark(player, "AddMaxCards", 1)
      else
        player.room:addPlayerMark(player, "MinusMaxCards", 1)
      end
    end
  end,
}

local woxingwolu = fk.CreateTriggerSkill{
  name = "woxingwolu",
  frequency = Skill.Wake,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    local events = player.room.logic:getEventsOfScope(GameEvent.MoveCards, 4, function (e)
      for _, move in ipairs(e.data) do
        if move.from and move.from == player.id and move.moveReason == fk.ReasonDiscard then
          return true
        end
      end
    end, Player.HistoryGame)
    return #events >= 3
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "AddMaxCards", 2)
  end,
}

shengwangguanghuan:addSkill(suoweiyiliu)
shengwangguanghuan:addSkill(prideofking)
shengwangguanghuan:addSkill(woxingwolu)

Fk:loadTranslationTable{
  ["ev__shengwangguanghuan"] = "圣王光环",
  ["designer:ev__shengwangguanghuan"] = "KINGDOM43",
  ["suoweiyiliu"] = "所谓一流",
  [":suoweiyiliu"] = "每轮开始时，你声明装备牌、魔法牌或基础牌中的{第X项}（X为轮数）。每轮结束时，若你为/不为于本轮内使用此项的牌最多的角色，你摸两张牌/弃置一张牌。",
  ["@[cardtypes]suoweiyiliu-round"] = "一流",
  --["@suoweiyiliu_record"] = "本轮最多使用",
  ["@suoweiyiliu-round"] = "所谓一流",
  ["prideofking"] = "王之骄傲",
  [":prideofking"] = "回合技，当你因弃置而失去牌后，你可获得弃牌堆里你于本轮内因使用而失去过的X张牌；然后若X大于1，你减少1点手牌上限（X为你的手牌上限）。",
  ["#prideofking"] = "王之骄傲：请选择%arg张牌获得之",
  ["woxingwolu"] = "我行我路",
  [":woxingwolu"] = "觉醒技，每轮结束时，若你因弃置而失去过至少三张牌，你增加2点手牌上限，将{ }里的描述改为“一项”。",

  ["$suoweiyiliu"] = "（日）呵呵，这就是帝王的实力！",
  ["$prideofking"] = "（日）哦~呵呵呵！不愧是帝王我！",
  ["$woxingwolu"] = "（日）我不会放弃，绝对不会！",
  ["~ev__shengwangguanghuan"] = "（日）帝王我，居然……",
}

local yuedu = General(extension, "ev__yuedu", "ev", 4, 4, General.Bigender)

local xudanyueluo = fk.CreateViewAsSkill{
  name = "xudanyueluo",
  anim_type = "control",
  pattern = "nullification,jink,dark_nightmare",
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == nil then
      table.insertIfNeed(names, "dark_nightmare")
    end
    for _, name in ipairs({"ev__jink","ev__nullification"}) do
      local card = Fk:cloneCard(name)
      if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return U.CardNameBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    if self.interaction.data == "ev__jink" then
      for _, id in ipairs(Self:getCardIds(Player.Judge)) do
        return Fk:getCardById(to_select).color == Fk:getCardById(id).color
      end
    elseif self.interaction.data == "ev__nullification" then
      for _, id in ipairs(Self:getCardIds(Player.Judge)) do
        return Fk:getCardById(to_select).color ~= Fk:getCardById(id).color
      end
    elseif self.interaction.data == "dark_nightmare" then
      return Fk:getCardById(to_select).color == Card.Black and Fk:getCardById(to_select).type ~= Card.TypeTrick
    end
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  after_use = function(self, player, use)
    if use.card.trueName == "dark_nightmare" then
      player:drawCards(1, self.name)
    end
  end,
  enabled_at_play = function(self, player)
    return not player:hasDelayedTrick("dark_nightmare")
  end,
  enabled_at_response = function(self, player, response)
    return #player:getCardIds(Player.Judge) > 0 and not response
  end
}

local yuejintianji = fk.CreateTriggerSkill{
  name = "yuejintianji",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
    return target == player and player:hasSkill(self) and player.phase == Player.Start and #table.filter(player:getCardIds(Player.Judge), function (id)
      return Fk:getCardById(id).suit == Card.Spade end) > 0
    else
      return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and data.from ~= player
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local cards = table.filter(player:getCardIds(Player.Judge), function (id) return Fk:getCardById(id).suit == Card.Spade end)
      local ids, choice = U.askforChooseCardsAndChoice(player, cards, {"OK", "cancel"}, self.name, "#yuejintianji")
      if choice ~= "cancel" then
        self.cost_data = ids
        return true
      end
    else
      return player.room:askForSkillInvoke(data.from, self.name, nil, "#yuejintianji-invoke::"..player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:useVirtualCard("meteor_falling", self.cost_data, player, room:getOtherPlayers(player), self.name, true)
    else
      if #player:getCardIds(Player.Judge) > 0 then
        local id = room:askForCardChosen(data.from, player, "j", self.name)
        room:obtainCard(data.from, id, false, fk.ReasonPrey)
      end
      return true
    end
  end,
}

yuedu:addSkill(xudanyueluo)
yuedu:addSkill(yuejintianji)

Fk:loadTranslationTable{
  ["ev__yuedu"] = "月读",
  ["designer:ev__yuedu"] = "次氯酸",
  ["xudanyueluo"] = "虚诞月落",
  ["xudanyueluo_act&"] = "虚诞月落",
  [":xudanyueluo"] = "出牌阶段，你可将一张黑色非魔法牌当【漆黑梦魇】对自己使用，然后你摸一张牌。你可将与你判定区里的牌颜色相同/不同的牌当【闪】/【魔法禁令】使用。",
  [":xudanyueluo_act&"] = "你可将一张黑色非魔法牌当【漆黑梦魇】对自己使用，然后你摸一张牌。",
  ["#xudanyueluo"] = "你可将一张黑色非魔法牌当【漆黑梦魇】对自己使用",
  ["yuejintianji"] = "月烬天极",
  [":yuejintianji"] = "准备阶段，你可将判定区里的一张黑桃牌当【星辰陨落】使用。当你受到其他角色使用【杀】造成的伤害时，其可防止此伤害，获得你判定区里的一张牌。",
  ["#yuejintianji"] = "你可将判定区里的一张黑桃牌当【星辰陨落】使用",
  ["#yuejintianji-invoke"] = "你可以防止此伤害，获得%dest判定区里的一张牌",
}
local yixienamei = General(extension, "ev__yixienamei", "ev", 4, 4, General.Female)

local shencizhiwen = fk.CreateActiveSkill{
  name = "shencizhiwen",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select).hp > 1
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    target:drawCards(1, self.name)
    room:loseHp(target, 1, self.name)
    room:addPlayerMark(target, "@@shencizhiwen")
  end,
}

local shencizhiwen_attackrange = fk.CreateAttackRangeSkill{
  name = "#shencizhiwen_attackrange",
  correct_func = function (self, from, to)
    if from:getMark("@@shencizhiwen") > 0 then
      return 1
    end
  end,
}

local shencizhiwen_trigger = fk.CreateTriggerSkill{
  name = "#shencizhiwen_trigger",
  mute = true,
  events = {fk.DamageCaused},
  --frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and target and target:getMark("@@shencizhiwen") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,

  refresh_events = {fk.Damage, fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and target and target:getMark("@@shencizhiwen") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.Damage then
      player.room:setPlayerMark(target, "@@shencizhiwen", 0)
    elseif event == fk.TurnStart then
      player.room:addPlayerMark(target, "shencizhiwen-turn")
    elseif event == fk.TurnEnd then
      if target:getMark("shencizhiwen-turn") > 0 then
        player.room:setPlayerMark(target, "@@shencizhiwen", 0)
      end
    end
  end,
}

local mieshizhiwu = fk.CreateTriggerSkill{
  name = "mieshizhiwu",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p) return p.hp == 1 end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 99, "#mieshizhiwu-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = table.map(tos, Util.Id2PlayerMapper)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(self.cost_data) do
      room:addPlayerMark(p, "@@mieshizhiwu")
      p:gainAnExtraTurn(true)
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and target:getMark("@@mieshizhiwu") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(target, "mieshizhiwu-turn")
    player.room:setPlayerMark(target, "@@mieshizhiwu", 0)
    target:turnOver()
  end,
}

local mieshizhiwu_prohibit = fk.CreateProhibitSkill{
  name = "#mieshizhiwu_prohibit",
  is_prohibited = function(self, from, to, card)
    return from:getMark("mieshizhiwu-turn") > 0 and from ~= to
  end,
}

shencizhiwen:addRelatedSkill(shencizhiwen_trigger)
shencizhiwen:addRelatedSkill(shencizhiwen_attackrange)
mieshizhiwu:addRelatedSkill(mieshizhiwu_prohibit)
yixienamei:addSkill(shencizhiwen)
yixienamei:addSkill(mieshizhiwu)
Fk:loadTranslationTable{
  ["ev__yixienamei"] = "伊邪那美",
  ["designer:ev__yixienamei"] = "次氯酸",
  ["shencizhiwen"] = "神赐之吻",
  [":shencizhiwen"] = "阶段技，你可令一名体力值大于1的角色摸一张牌，失去1点体力，然后其攻击范围与造成的伤害均+1，直至其造成伤害后或其下回合结束。",
  ["#shencizhiwen"] = "你可令一名体力值大于1的角色摸一张牌，失去1点体力",
  ["@@shencizhiwen"] = "神赐之吻",
  ["mieshizhiwu"] = "灭世之舞",
  [":mieshizhiwu"] = "限定技，一轮结束时，你可令任意名体力值为1的角色各获得一个额外回合；这些额外回合开始时，当前回合角色翻面，且于此回合内不能对除其外的角色使用牌。",
  ["#mieshizhiwu-choose"] = "你可令任意名体力值为1的角色各获得一个额外回合",
  ["@@mieshizhiwu"] = "灭世之舞",
  ["#mieshizhiwu_prohibit"] = "灭世之舞",
}

local thirtyseven = General(extension, "ev__thirtyseven", "ev", 3, 3, General.Female)

local function isPrime(num)
  -- 小于2的数不是质数
  if num < 2 then
      return false
  end
  -- 2是最小的质数
  if num == 2 then
      return true
  end
  -- 偶数不是质数
  if num % 2 == 0 then
      return false
  end
  -- 只检查奇数因子
  for i = 3, math.sqrt(num), 2 do
      if num % i == 0 then
          return false
      end
  end
  return true
end

local shudeqidi = fk.CreateTriggerSkill{
  name = "shudeqidi",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player ~= target or not player:hasSkill(self) or not U.IsUsingHandcard(player, data) then return false end
    local room = player.room
    local logic = room.logic
    local use_event = logic:getCurrentEvent()
    local events = logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    local last_find = false
    for i = #events, 1, -1 do
      local e = events[i]
      if e.data[1].from == player.id then
        if e.id == use_event.id then
          last_find = true
        elseif last_find then
          local last_use = e.data[1]
          return data.card.number % last_use.card.number ~= 0 and last_use.card.number % data.card.number ~= 0
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@$shudeqidi")
    table.insert(mark, data.card.id)
    room:setPlayerMark(player, "@$shudeqidi", mark)
    if isPrime(data.card.number) then
      local ids = room:getNCards(2)
      U.viewCards(player, ids, self.name)
    else
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.AfterCardsMove, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      return player:hasSkill(self) and target == player
    elseif event == fk.AfterCardsMove then
      if player:hasSkill(self) then
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Player.Hand then
            return true
          end
        end
      end
    elseif event == fk.EventLoseSkill then
      return target == player and data == self
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared or event == fk.AfterCardsMove then
      local num = 0
      if event == fk.AfterCardUseDeclared then
        num = data.card.number
      else
        local logic = room.logic
        local use_event = logic:getCurrentEvent()
        local events = logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
        for i = #events, 1, -1 do
          local e = events[i]
          if e.data[1].from == player.id then
            num = e.data[1].card.number
            break
          end
        end
      end
      for _, id in ipairs(player:getCardIds(Player.Hand)) do
        if num % Fk:getCardById(id).number ~= 0 and Fk:getCardById(id).number % num ~= 0 then
          if isPrime(Fk:getCardById(id).number) then
            room:setCardMark(Fk:getCardById(id), "@qidi-inhand", 2)
          else
            room:setCardMark(Fk:getCardById(id), "@qidi-inhand", 1)
          end
        else
          room:setCardMark(Fk:getCardById(id), "@qidi-inhand", 0)
        end
      end
    elseif event == fk.EventLoseSkill then
      U.clearHandMark(player, "@qidi-inhand")
    end
  end,
}

local buchongsuanshi = fk.CreateTriggerSkill{
  name = "buchongsuanshi",
  anim_type = "offensive",
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      local mark = player:getTableMark("@$shudeqidi")
      local n = 0
      for _, id in ipairs(mark) do
        n = n + Fk:getCardById(id).number
      end
      return n > player.room:getTag("RoundCount") * #player.room.alive_players
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = room:getTag("RoundCount") + 1
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, n, "#buchongsuanshi-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = table.map(tos, Util.Id2PlayerMapper)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@$shudeqidi", 0)
    for _, p in ipairs(self.cost_data) do
      local cardResponded = room:askForResponse(p, 'jink', nil, nil, true, nil, effect)
      if cardResponded then
        room:responseCard({
          from = p.id,
          card = cardResponded,
          responseToEvent = effect,
        })
      else
        room:damage({
          from = player,
          to = p,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}

thirtyseven:addSkill(shudeqidi)
thirtyseven:addSkill(buchongsuanshi)

Fk:loadTranslationTable{
  ["ev__thirtyseven"] = "37",
  ["designer:ev__thirtyseven"] = "风鸢",
  ["shudeqidi"] = "数的启迪",
  ["@$shudeqidi"] = "启迪",
  ["@qidi-inhand"] = "启迪",
  [":shudeqidi"] = "当你使用点数不为/为质数的手牌时，若此牌与你使用的上一张牌的点数均不为对方的倍数，你记录此牌，然后你可摸一张牌/观看牌堆顶的两张牌。",
  ["buchongsuanshi"] = "补充算式",
  [":buchongsuanshi"] = "每轮结束时，若你记录的牌的点数之和大于角色数与X之积，你可清除记录，令至多X+1名角色各选择一项：1.打出【闪】；2.受到你造成的1点伤害（X为轮数）。",
  ["#buchongsuanshi-choose"] = "补充算式：请选择角色并清除记录",
}

local Kagiyama = General(extension, "ev__kagiyama", "ev", 3, 3, General.Female)

local ev__tongku = fk.CreateTriggerSkill{
  name = "ev__tongku",
  anim_type = "special",
  derived_piles = {"jinx"},
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      if event == fk.TurnEnd then
        local ids = {}
        local logic = room.logic
        local events = logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable
        if not logic:getCurrentEvent():findParent(GameEvent.Turn, true) then return {} end
        local end_id = logic:getCurrentEvent():findParent(GameEvent.Turn, true).id
        for i = #events, 1, -1 do
          local e = events[i]
          if e.id < end_id then break end
          for _, move in ipairs(e.data) do
            if move.toArea == Card.DiscardPile and 
            (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonResonpse or move.moveReason == fk.ReasonJudge) then
              for _, info in ipairs(move.moveInfo) do
                if Fk:getCardById(info.cardId).color == Card.Black then
                  table.insertIfNeed(ids, info.cardId)
                end
              end
            end
          end
        end
        local cards = table.simpleClone(ids)
        for _, id in ipairs(cards) do
          if room:getCardArea(id) ~= Card.DiscardPile then
            table.removeOne(ids, id)
          end
        end
        if #ids > 0 then
          self.cost_data = ids
          return true
        end
      else
        return target ~= player and table.contains(TargetGroup:getRealTargets(data.tos), player.id) and not target.dead and
        table.every(player.room.alive_players, function(p) return not p.dying end) and #player:getPile("jinx") > 0 
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      player:addToPile("jinx", self.cost_data, true, self.name)
    else
      local room = player.room
      --room:askForUseCard(player, "", ".|.|.|jinx", "#ev__tongku-use::"..target.id, true, {must_targets = {target.id}, bypass_distances = true, bypass_times = true})
      local id = room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|jinx", "#ev__tongku-use::"..target.id, "jinx")
      if #id > 0 then
        id = id[1]
      else
        id = table.random(player:getPile("jinx"))
      end
      local card = Fk:getCardById(id)
      local canUse = player:canUseTo(card, target, {bypass_distances = true, bypass_times = true}) and not
      (card.skill:getMinTargetNum() == 0 and not card.multiple_targets)
      local tos = {{target.id}}
      if canUse and card.skill:getMinTargetNum() == 2 then
        local seconds = {}
        Self = player
        for _, second in ipairs(room:getOtherPlayers(target)) do
          if card.skill:targetFilter(second.id, {target.id}, {}, card) then
            table.insert(seconds, second.id)
          end
        end
        if #seconds > 0 then
          local second = room:askForChoosePlayers(player, seconds, 1, 1, "#ev__tongku-second:::"..card:toLogString(), self.name, false, true)
          table.insert(tos, second)
        else
          canUse = false
        end
      end
      if canUse then
        local use = {
          from = player.id,
          tos = tos,
          card = card,
          extraUse = true,
        }
        use.extra_data = use.extra_data or {}
        room:useCard(use)
      else
        --room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
      end
    end
  end,
}

local ev__eyun = fk.CreateTriggerSkill{
  name = "ev__eyun",
  events = {fk.EventPhaseStart, fk.AfterDrawPileShuffle},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Start and #player:getPile("jinx") >= math.max(player:getLostHp(), 1)
    else
      return player:hasSkill(self) and #player:getPile("jinx") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Start then
      local n = math.max(player:getLostHp(), 1)
      local cards = room:askForCard(player, 1, n, false, self.name, false, ".|.|.|jinx|.|.", "#ev__eyun-get", "jinx")
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
    else
      local armors = table.filter(player:getPile("jinx"), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeArmor end)
      if #armors > 0 then
        U.askForDistribution(player, armors, room:getOtherPlayers(player), self.name, #armors, #armors, "#ev__eyun", "jinx")
      end
      room:moveCardTo(player:getPile("jinx"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true)
    end
  end
}

Kagiyama:addSkill(ev__tongku)
Kagiyama:addSkill(ev__eyun)

Fk:loadTranslationTable{
  ["ev__kagiyama"] = "键山雏",
  ["designer:ev__kagiyama"] = "KINGDOM43",
  ["illustrator:ev__kagiyama"] = "まひる",
  ["jinx"] = "厄",
  ["ev__tongku"] = "痛苦之流",
  [":ev__tongku"] = "锁定技，一名角色的回合结束时，你将于此回合内因判定、弃置或打出而置入弃牌堆的黑色牌置于角色牌上，称为“厄”。其他角色对你使用的牌结算结束后，若没有角色处于濒死状态，你对其使用一张“厄”。",
  ["#ev__tongku-use"] = "痛苦之流：请对%dest使用一张“厄”",
  ["#ev__tongku-second"] = "请指定%arg的子目标（如借刀被杀的目标）",
  ["ev__eyun"] = "厄运之轮",
  [":ev__eyun"] = "准备阶段，你可获得一至X张“厄”（X为你已损失的体力值且至少为1）。牌堆洗切后，你将“厄”中的防具牌交给其他角色，将所有“厄”置入弃牌堆。",
  ["#ev__eyun-get"] = "请选择获得的“厄”",
  ["#ev__eyun"] = "请将“厄”中的防具牌交给其他角色",
}

local peacock = General(extension, "ev__peacock", "ev", 3, 3, General.Female)
local milizhijing = fk.CreateTriggerSkill{
  name = "milizhijing",
  derived_piles = {"ev__ling"},
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and #player:getPile("ev__ling") < 4
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#milizhijing-card")
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("ev__ling", self.cost_data, true, self.name)
    room:setPlayerMark(target, "jiaoxie-turn", player.id)
  end
}

local milizhijing_effect = fk.CreateProhibitSkill{
  name = "#milizhijing_effect",
  prohibit_use = function(self, player, card)
    if player:getMark("jiaoxie-turn") ~= 0 then
      local room = Fk:currentRoom()
      local target = room:getPlayerById(player:getMark("jiaoxie-turn"))
      if target and not target.dead and #target:getPile("ev__ling") > 0 then
        return card and card.name == "ev__slash" and table.find(target:getPile("ev__ling"), function (id)
          return Fk:getCardById(id).suit == card.suit
        end)
      end
    end
  end,
}

local quewuzhanji = fk.CreateTriggerSkill{
  name = "quewuzhanji",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and #player:getPile("ev__ling") >= player.hp
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #player:getPile("ev__ling")
    room:moveCardTo(player:getPile("ev__ling"), Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
    local cards = room:askForDiscard(player, n, n, true, self.name, true, ".", "#quewuzhanji:::"..n)
    if #cards > 0 then
      player:drawCards(n, self.name)
      local types = {}
      for _, id in ipairs(cards) do
        table.insertIfNeed(types, Fk:getCardById(id).type)
      end
      room:setPlayerMark(player, "@quewuzhanji-turn", #types)
    end
  end
}

local quewuzhanji_attackrange = fk.CreateAttackRangeSkill{
  name = "#quewuzhanji_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("quewuzhanji") and from:getMark("@quewuzhanji-turn") > 0 then
      return from:getMark("@quewuzhanji-turn") - 1
    end
  end,
}

local quewuzhanji_targetmod = fk.CreateTargetModSkill{
  name = "#quewuzhanji_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("quewuzhanji") and skill.trueName == "slash_skill" and card.trueName == "slash" and scope == Player.HistoryPhase
    and player:getMark("@quewuzhanji-turn") > 0 then
      return player:getMark("@quewuzhanji-turn") - 1
    end
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("@quewuzhanji-turn") > 0 then
      return player:getMark("@quewuzhanji-turn") - 1
    end
  end,
}

milizhijing:addRelatedSkill(milizhijing_effect)
quewuzhanji:addRelatedSkill(quewuzhanji_attackrange)
quewuzhanji:addRelatedSkill(quewuzhanji_targetmod)
peacock:addSkill(milizhijing)
peacock:addSkill(quewuzhanji)

Fk:loadTranslationTable{
  ["ev__peacock"] = "孔雀明王",
  ["designer:ev__peacock"] = "次氯酸",
  ["milizhijing"] = "迷离之境",
  [":milizhijing"] = "回合技（始），若“翎”数小于4，你可将一张手牌置于角色牌上，称为“翎”，令其于此回合内不能使用或打出与“翎”花色相同的普通【杀】。",
  ["ev__ling"] = "翎",
  ["#milizhijing_effect"] = "缴械",
  ["jiaoxie-turn"] = "<font color=\"#D2042D\">缴械</font>",
  ["#milizhijing-card"] = "你可将一张手牌置于角色牌上",
  ["quewuzhanji"] = "雀舞斩棘",
  [":quewuzhanji"] = "阶段技（始），若“翎”数不小于你的体力值，你获得所有“翎”，然后你可弃置等量张牌，摸等量张牌，令你的攻击范围，使用【杀】的次数上限与额定目标数于本回合内+X（X为你以此法弃置的牌的类别数-1）。",
  ["#quewuzhanji"] = "雀舞斩棘：你可以弃置%arg张牌，摸等量牌",
  ["@quewuzhanji-turn"] = "雀舞斩棘",
}

local marchseven = General(extension, "ev__marchseven", "ev", 3, 3, General.Female)

local mengjizhengyi = fk.CreateActiveSkill{
  name = "mengjizhengyi",
  prompt = "#mengjizhengyi",
  mute = true,
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.TrueFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):getMark("mengjizhengyi-phase") > 0
    and not Fk:currentRoom():getPlayerById(to_select):isAllNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:notifySkillInvoked(player, self.name, "support")
    player:broadcastSkillInvoke(self.name, table.random({1,2}))
    target:addToPile("shield", effect.cards, true, self.name)
    local id = room:askForCardChosen(player, target, "hej", self.name)
    if id then
      target:addToPile("shield", id, true, self.name)
    end
  end,
}

local mengjizhengyi_trigger = fk.CreateTriggerSkill{
  name = "#mengjizhengyi_trigger",
  mute = true,
  events = {"fk.ShieldCosted"},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and EV.isFriend(player, target) and data.from and player:usedSkillTimes(self.name) < 2
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".", "#mengjizhengyi-slash::"..data.from.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "mengjizhengyi", "offensive")
    player:broadcastSkillInvoke("mengjizhengyi", table.random({3,4}))
    player.room:useVirtualCard("ev_ice__slash", self.cost_data, player, data.from, self.name, true)
  end,

  refresh_events = {fk.StartPlayCard},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if EV.isFriend(player, p) then
        room:setPlayerMark(p, "mengjizhengyi-phase", 1)
      end
    end
  end,
}

local bingkejianyu = fk.CreateActiveSkill{
  name = "bingkejianyu",
  frequency = Skill.Limited,
  mute = true,
  prompt = "#bingkejianyu",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and Fk:getCardById(to_select).type == Card.TypeTrick then
      local card = Fk:cloneCard("snow_storm")
      card:addSubcard(to_select)
      return not Self:prohibitUse(card)
    end
  end,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    player:broadcastSkillInvoke(self.name, table.random({1,2}))
    room:notifySkillInvoked(player, self.name)
    room:useVirtualCard("snow_storm", use.cards, player, room:getOtherPlayers(player), self.name, true)
  end,
}

local bingkejianyu_prohibit = fk.CreateProhibitSkill{
  name = "#bingkejianyu_prohibit",
  is_prohibited = function(self, from, to, card)
    return from:hasSkill("bingkejianyu") and card.skillName == "bingkejianyu" and EV.isFriend(from, to)
  end,
}

local bingkejianyu_trigger = fk.CreateTriggerSkill{
  name = "#bingkejianyu_trigger",
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and data.card and data.card.skillName == "bingkejianyu"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "bingkejianyu", "offensive")
    player:broadcastSkillInvoke("bingkejianyu", table.random({3,4}))
    if target.faceup then
      target:turnOver()
    end
    return true
  end
}

mengjizhengyi:addRelatedSkill(mengjizhengyi_trigger)
bingkejianyu:addRelatedSkill(bingkejianyu_prohibit)
bingkejianyu:addRelatedSkill(bingkejianyu_trigger)
marchseven:addSkill(mengjizhengyi)
marchseven:addSkill(bingkejianyu)

Fk:loadTranslationTable{
  ["ev__marchseven"] = "三月七",
  ["designer:ev__marchseven"] = "懂太师",
  ["mengjizhengyi"] = "可爱即正义",
  [":mengjizhengyi"] = "阶段技，你可将你和一名己方角色区域内的各一张牌置为其护盾。回合技（2），当己方角色消耗护盾后，你可将一张牌当冰【杀】对伤害来源使用。",
  ["#mengjizhengyi"] = "你可选择你区域内的一张牌和一名己方角色",
  ["#mengjizhengyi-slash"] = "你可将一张牌当冰【杀】对%dest使用",
  ["bingkejianyu"] = "冰刻箭雨时",
  ["#bingkejianyu_prohibit"] = "冰刻箭雨",
  ["#bingkejianyu"] = "你可将一张魔法牌当【暴风雪】使用",
  [":bingkejianyu"] = "限定技，出牌阶段，你可将一张魔法牌当【暴风雪】使用，且己方角色不是此牌的合法目标；当一名角色受到此牌造成的伤害时，其防止之，翻至背面。",

  ["$mengjizhengyi1"] = "本姑娘出马，怎么可能会输嘛～",
  ["$mengjizhengyi2"] = "乖乖站好，这就给你加个祝福～",
  ["$mengjizhengyi3"] = "桃花影落飞神剑～",
  ["$mengjizhengyi4"] = "来尝尝本姑娘的厉害～",
  ["$bingkejianyu1"] = "我一个可以打十个！",
  ["$bingkejianyu2"] = "左青龙，右白虎，少吃碳水化合物——看招！",
  ["$bingkejianyu3"] = "冻结吧！",
  ["$bingkejianyu4"] = "别小瞧本姑娘！",
  ["~ev__marchseven"] = "呀啊！不讲武德。。。",
}



return extension